home *** CD-ROM | disk | FTP | other *** search
/ Programming Windows (5th Edition) / Programming Windows, 5th ed. - Companion CD (097-0002183)(1999).iso / Chap02 / ScrnSize / ScrnSize.c next >
Encoding:
C/C++ Source or Header  |  1998-10-09  |  1.4 KB  |  44 lines

  1. /*-----------------------------------------------------
  2.    SCRNSIZE.C -- Displays screen size in a message box
  3.                  (c) Charles Petzold, 1998
  4.   -----------------------------------------------------*/
  5.  
  6. #include <windows.h>
  7. #include <tchar.h>     
  8. #include <stdio.h>     
  9.  
  10. int CDECL MessageBoxPrintf (TCHAR * szCaption, TCHAR * szFormat, ...)
  11. {
  12.      TCHAR   szBuffer [1024] ;
  13.      va_list pArgList ;
  14.  
  15.           // The va_start macro (defined in STDARG.H) is usually equivalent to:
  16.           // pArgList = (char *) &szFormat + sizeof (szFormat) ;
  17.  
  18.      va_start (pArgList, szFormat) ;
  19.  
  20.           // The last argument to wvsprintf points to the arguments
  21.  
  22.      _vsntprintf (szBuffer, sizeof (szBuffer) / sizeof (TCHAR), 
  23.                   szFormat, pArgList) ;
  24.  
  25.           // The va_end macro just zeroes out pArgList for no good reason
  26.  
  27.      va_end (pArgList) ;
  28.  
  29.      return MessageBox (NULL, szBuffer, szCaption, 0) ;
  30. }
  31.  
  32. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  33.                     PSTR szCmdLine, int iCmdShow) 
  34. {
  35.      int cxScreen, cyScreen ;
  36.  
  37.      cxScreen = GetSystemMetrics (SM_CXSCREEN) ;
  38.      cyScreen = GetSystemMetrics (SM_CYSCREEN) ;
  39.  
  40.      MessageBoxPrintf (TEXT ("ScrnSize"), 
  41.                        TEXT ("The screen is %i pixels wide by %i pixels high."),
  42.                        cxScreen, cyScreen) ;
  43.      return 0 ;
  44. }